<?php

namespace app\zmt\validate;

use think\Validate;

class GoodsValidate extends Validate
{
    protected $rule = [
        'title' => 'require|max:255',
        'image' => 'require',
        'price' => 'require|float',
        'type' => 'require|integer',
        'switch' => 'require|in:0,1,2', // 商品状态
    ];

    protected $message = [
        'title.require' => '标题不能为空',
        'title.max' => '标题不能超过255个字符',
        'image.require' => '封面图不能为空',
        'price.require' => '价格不能为空',
        'price.float' => '价格必须是数字',
        'type.require' => '运营类型不能为空',
        'type.integer' => '运营类型必须是整数',
        'switch.require' => '商品状态不能为空',
        'switch.in' => '商品状态值不合法',
    ];

    protected $scene = [
        'addPost' => ['title', 'image', 'price', 'type', 'switch'],
        'editPost' => ['title', 'image', 'price', 'type', 'switch'],
    ];
}

